import { defineStore } from 'pinia'
import { getConfig } from '@/api/app'

interface AppSate {
    config: Record<string, any>
}
export const useAppStore = defineStore({
    id: 'appStore',
    state: (): AppSate => ({
        config: {}
    }),
    getters: {
        getWebsiteConfig: (state) => state.config.website || {},
        getLoginConfig: (state) => state.config.login || {},
        getTabbarConfig: (state) => state.config.tabbar || [],
        getStyleConfig: (state) => state.config.style || {},
        getH5Config: (state) => state.config.h5 || {},
        getCopyright: (state) => state.config.copyright || {},
		getWebType: (state) => (state.config.website && state.config.website.webType !== undefined) ? state.config.website.webType : 0,
		getSalesDay: (state) => (state.config.website && state.config.website.afterSalesDay !== undefined) ? state.config.website.afterSalesDay : 0,
    },
    actions: {
        getImageUrl(url: string) {
            return url ? `${this.config.domain}${url}` : ''
        },
        async getConfig() {
            const data = await getConfig()
            const tabbar= [
                {
                    "name": "首页",
                    "selected": "https://mczxshop.oss-rg-china-mainland.aliyuncs.com/image/20241021/b893dbcb-2257-4d97-a81c-225cb34e2ba7.png",
                    "unselected": "https://mczxshop.oss-rg-china-mainland.aliyuncs.com/image/20241022/496201cb-9af2-4c89-98dd-bf728a65f194.png",
                    "link": "{\"path\":\"/packageA/pages/engineer/engineer\",\"name\":\"商城首页\",\"type\":\"shop\"}"
                },
                {
                    "name": "我的",
                    "selected": "https://mczxshop.oss-rg-china-mainland.aliyuncs.com/image/20241021/cb088ded-6b98-4fc9-bb79-c7c41772470c.png",
                    "unselected": "https://mczxshop.oss-rg-china-mainland.aliyuncs.com/image/20241022/caa07bb3-bec8-4df0-b149-597903b9693e.png",
                    "link": "{\"path\":\"/pages/user/user\",\"name\":\"个人中心\",\"type\":\"shop\"}"
                }
            ]
            this.config = data
            this.config.tabbar=tabbar
            console.log(this.config, 45678913)
        }
    }
})
